package com.Inter.D04TCP;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        // 服务端
        // 利用TCP协议接收数据

        // 1.创建对象
        ServerSocket serverSocket = new ServerSocket(10000);

        // 2.监听客户端的连接
        Socket accept = serverSocket.accept();

        // 3.从连接通道中获取输入流读取数据
        // InputStream is = accept.getInputStream();
        // InputStreamReader isr = new InputStreamReader(is);
        // BufferedReader br = new BufferedReader(isr);
        BufferedReader br = new BufferedReader(new InputStreamReader(accept.getInputStream()));
        int b;
        while ((b = br.read()) != -1) {
            System.out.print((char) b);
        }

        // 4.释放资源
        accept.close();
        serverSocket.close();
    }
}
